function Set-DependencyProperty {
PARAM(
#   [Parameter(Position=0,Mandatory=$true)]
   $Property
,
   $Value
,
#   [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
   $Element
,
#   [Parameter()]
   [Switch]$Passthru
)
PROCESS {
   if($_) { $Element = $_ }
   if(!$Element) { throw "No element to set dependency properties on!" }

   trap { 
      Write-Host "ERROR Setting Dependency Property" -Fore Red
      Write-Host "Trying to set $Property to $Value" -Fore Red
      continue
   }
   if($Property.GetType() -eq ([System.Windows.DependencyProperty]) -or
      $Property.GetType().IsSubclassOf(([System.Windows.DependencyProperty]))
   ){
      trap { 
         Write-Host "ERROR Setting Dependency Property" -Fore Red
         Write-Host "Trying to set $($Property.FullName) to $Value" -Fore Red
         continue
      }
      $Element.SetValue($Property, ($Value -as $Property.PropertyType))
   } else {
      $Class = ""
      if("$Property".Contains(".")) {
         $Class,$Property = "$Property".Split(".")
      }
         
      if($DependencyProperties.ContainsKey("$Property")){
         $fields = @($DependencyProperties[$Property] | ? { $_.DeclaringType -like "*$Class" -and ($Value -as ([type]$_.PropertyType))})
         if($fields.Count -eq 0 ) { 
            $fields = @($DependencyProperties[$Property] | ? { $_.DeclaringType -like "*$Class" })
         }
         if($fields.Count) {
            $success = $false
            foreach($field in $fields) {
               trap { 
                  Write-Host "ERROR Setting Dependency Property" -Fore Red
                  Write-Host "Trying to set $($field.DeclaringType)::$($field.Name) to $Value -as $($field.PropertyType)" -Fore Red
                  Write-Host $_
                  Write-Host
                  continue
               }
               $Element.SetValue( ([type]$field.DeclaringType)::"$($field.Name)", ($Value -as ([type]$field.PropertyType)))
               if($?) { $success = $true; break }
            }
            if(!$success) { throw "food" }
         } else {
            Write-Host "Couldn't find the right property: $Class.$Property on $($Element.GetType().Name) of type $($field.PropertyType)" -Fore Red      
         }
      } else {
         Write-Host "Unknown Dependency Property Key: $Property on $($Element.GetType().Name)" -Fore Red      
      }  
   }
   if( $Passthru ) {
      $Element
   }
}
}

# SIG # Begin signature block
# MIILCQYJKoZI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